var hasPostMessage = false;

function inject(){
      // 注入js
      var s = document.createElement('script');
      s.src = chrome.extension.getURL('js/autobuy.js');
      s.onload = function() {
          this.parentNode.removeChild(this);
      };
      (document.head || document.documentElement).appendChild(s);
}

// 注入js
inject();
// 监听事件
chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        if(hasPostMessage == false){
            window.postMessage({price: request.price, number:request.number}, '*');
            hasPostMessage = true;
            console.log("content.js 向autobuy.js通知,Price="+request.price+", number="+request.number);
        }else{
            console.log("content.js 已经向autobuy.js通知过");
        }   
    }
);
